ItemTooltipEvent.addListener(event => {
    var {itemStack, entity, toolTip, flags} =event
    if (itemStack.getCapability(ForgeCapabilities.ENERGY).isPresent()) {
        var capability = itemStack.getCapability(ForgeCapabilities.ENERGY).orElse(null)
        var { energyStored, maxEnergyStored } = capability
        for (let index = 0; index < toolTip.length; index++) {
            var Component = toolTip.get(index);
            if (Component.getString() == "IndexOfShowEnergy") {
                var { newNumber: energyStored_, unitName: unit1 } = unitChanger(energyStored)
                var { newNumber: maxEnergyStored_, unitName: unit2 } = unitChanger(maxEnergyStored)
                toolTip.set(index, Component.translatable("desc.eou.item.durabilityofenergy", energyStored_.toFixed(2).toString() + unit1, maxEnergyStored_.toFixed(2).toString() + unit2).green())
            }
            // if (Component.contents instanceof TranslatableContents_) {
            //     var key = Component.contents.getKey()
            //     if (key == "item.durability") {
            //         toolTip.set(index, Component.translatable("item.eou.durabilityofenergy", energyStored, maxEnergyStored).green())
            //     }
            // }
        }
    }
})

function unitChanger(number) {
    var unit = ""
    var newNumber = number

    for (let index = 0; index <= 2; index++) {
        newNumber = newNumber / 1000
        if (newNumber <= 1) {
            switch (index) {
                default: unit = ""
                    break;
                case 1: unit = "KFE"
                    break;
                case 2: unit = "MFE"
                    break;
            }
            break
        }
    }
    return { newNumber: newNumber*1000, unitName: unit }
}